import { defineStore } from 'pinia'
import { fundationInfo, checkInfo, developInfo, hirePace } from '../../api/homePage'

export const useHomePageStore = defineStore('HomePage', {
  state: () => ({
    // 基本统计信息
    peopleTotals: {
      total: 0,
      badCount: 0,
      goodCount: 0
    },
    checks: {
      total: 0,
      wagesCount:{}
    },
    developInfos: {
      total: 0,
      wagesCount:[]
    },
    hireInfos: {
      total: 0,
      wagesCount:{}
    },
  }),
  actions: {
    // 获取总人数及男女人数
    async fetchPeopleTotals() {
      try {
        const res = await fundationInfo()

        Object.assign(this.peopleTotals, res.data) //整体赋值

        console.log('后端获取的peopleTotals',this.peopleTotals)
      } catch (error) {
        this.error = 'Failed to fetch infos.'
      }
    },
    // 获取考勤信息
    async fetchCheckInfos() {
      try {
        const res = await checkInfo()

        Object.assign(this.checks, res.data) //整体赋值

        console.log('后端获取的checks',this.checks)
      } catch (error) {
        this.error = 'Failed to fetch infos.'
      }
    },
    // 获取培训信息报表——折线图  +  部门人员统计——饼状图
    async fetchDevelopInfos() {
      try {
        const res = await developInfo()

        Object.assign(this.developInfos, res.data) //整体赋值

        console.log('后端获取的developInfos',this.developInfos)
      } catch (error) {
        this.error = 'Failed to fetch infos.'
      }
    },
    // 获取招聘信息
    async fetchHireInfos() {
      try {
        const res = await hirePace()

        Object.assign(this.hireInfos, res.data) //整体赋值

        console.log('后端获取的hireInfos',this.hireInfos)
      } catch (error) {
        this.error = 'Failed to fetch infos.'
      }
    },
  }
})
